package day01;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/21 15:37
 * 力扣 215 数组中的第K个最大元素
 */
public class HeapPractice01 {
    public int findKthLargest(int[] nums, int k) {
        ArrayMinHeap heap = new ArrayMinHeap(k);
        for (int i = 0; i < k; i++) {
            heap.offer(nums[i]);
        }
        for (int i = k; i < nums.length; i++) {
            if (nums[i] > heap.peek()) {
                heap.replace(nums[i]);
            }
        }
        return heap.peek();
    }
}
